//
//  JKSettingTableViewController.swift
//  afanti
//
//  Created by albert on 16/5/7.
//  Copyright © 2016年 albert. All rights reserved.
//

import UIKit

class JKSettingTableViewController: JKBaseSettingTableViewController {
    
    /** 弹窗 */
    func alert(){
        if #available(iOS 8.0, *) {
            let alert = UIAlertController(title: "提示", message: "确定清空缓存？", preferredStyle: UIAlertControllerStyle.Alert)
            
            alert.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.Default, handler: nil))
            alert.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
                
                }))
            
            self.presentViewController(alert, animated: true, completion: nil)
            
        } else {
            let alert7 = UIAlertView(title: "提示", message: "确定清空缓存？", delegate: nil, cancelButtonTitle: "取消", otherButtonTitles: "确定")//(title: "提示", message: "暂无消息", delegate: nil, cancelButtonTitle: "确定")
            alert7.show()
            
        }
    }
    
    //MARK: - 建议反馈控制器
    func setupDeviceVc(title: String){
        let deviceVc = JKAdviceViewController()
        deviceVc.title = title
        self.navigationController?.pushViewController(deviceVc, animated: true)
    }
    
    //MARK: - 初始化数据
    func setupCellData(){
        // 第一组
        let item1 = JKSettingItem.item("清空缓存") { () -> Void in
            self.alert()
        }
        
        let item2 = JKSettingItem.item("使用帮助") { () -> Void in
            print("使用帮助")
        }
        
        let item3 = JKSettingItem.item("应用评价") { () -> Void in
            print("应用评价")
        }
        
        let item4 = JKSettingItem.item("关于") { () -> Void in
            let aboutVc = JKAboutViewController()
            aboutVc.title = "关于"
            self.navigationController?.pushViewController(aboutVc, animated: true)
        }
        let group1 = JKSettingGroup()
        group1.items = [item1, item2, item3, item4]
        cellData.append(group1)
        
        // 第二组
        let item5 = JKSettingItem.item("意见反馈") { () -> Void in
            self.setupDeviceVc("意见反馈")
        }
        let group2 = JKSettingGroup()
        group2.items = [item5]
        cellData.append(group2)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 初始化数据
        setupCellData()
    }
    
    override func viewWillAppear(animated: Bool) {
        self.navigationController?.navigationBar.hidden = false
    }
}
